﻿using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace Calculator.Tests
{
    [TestFixture]
    public class CalculatorTests
    {
        [TestCase(2, 3, 5)]
        [TestCase(3, -1, 2)]
        [TestCase(-1, -2, -3)]
        public void Add_AdditionOfTwoValues_ReturnsProperSum(int a, int b, int expectedSum)
        {
            var calc = new Calculator();
            var sum = calc.Add(a, b);

            Assert.AreEqual(expectedSum, sum);
        }

        [Test]
        public void Add_OptionalAddendsArrayIsNull_ReturnsProperSum()
        {
            var calc = new Calculator();
            var sum = calc.Add(2, 3, null);

            Assert.AreEqual(5, sum);
        }

        [Test]
        public void Add_OptionalAddendsArrayIsEmpty_ReturnsProperSum()
        {
            var calc = new Calculator();
            var sum = calc.Add(2, 3, new int[] {});

            Assert.AreEqual(5, sum);
        }

        [Test]
        public void Add_OptionalAddendsArrayContainsOneElement_ReturnsProperSum()
        {
            var calc = new Calculator();
            var sum = calc.Add(2, 3, 4);

            Assert.AreEqual(9, sum);
        }

        [Test]
        public void Add_OptionalAddendsArrayContainsManyElements_ReturnsProperSum()
        {
            var calc = new Calculator();
            var sum = calc.Add(2, 3, 4, 5);

            Assert.AreEqual(14, sum);
        }

        [Test]
        public void Add_IntegerOverflows_DoesNotThrowException()
        {
            var calc = new Calculator();
            Assert.DoesNotThrow(() => calc.Add(int.MaxValue, 1));
        }

        [TestCase(5, 2, 2.5f)]
        [TestCase(-6, 2, -3.0f)]
        [TestCase(-10, -2, 5.0f)]
        public void Division_DivisionOfTwoValues_ReturnsProperValue(int a, int b, float expectedQuotient)
        {
            var calc = new Calculator();
            var quotient = calc.Divide(a, b);

            Assert.AreEqual(expectedQuotient, quotient);
        }

        [Test]
        public void Division_DivisionByZero_ThrowsAnException()
        {
            var calc = new Calculator();
            Assert.Throws<DivideByZeroException>(() => calc.Divide(4, 0));
        }
    }
}
